package SparkRDD.RDD算子.Actions

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.Test

/**
 *  countByKey 可以应用到数据倾斜，通过该方法可以查看Key对应的数据总数，为数据倾斜提供解决方案
 */
class countByKeyTest {

    val conf = new SparkConf().setMaster("local[6]").setAppName("sortBy")
    val sc   = new SparkContext(conf)

    @Test
    def countByKeyTest: Unit ={
      val rdd: RDD[(String, Double)] = sc.parallelize(Seq(("薯片",8.0),("可乐",3.0),("面包",4.5)))
      val result: collection.Map[String, Long] = rdd.countByKey()
      println(result)
    }

}
